package module.view
{
	import commons.PipeAwareModuleConstants;
	
	import flash.events.MouseEvent;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class ModuleSampleMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "ModuleSampleMediator";
		
		public function ModuleSampleMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void{
			moduleSample.btnMessage.addEventListener(MouseEvent.CLICK, onBtnMessageClick);
		}
		
		private function onBtnMessageClick(evt:MouseEvent):void{
			sendNotification(PipeAwareModuleConstants.SEND_MESSAGE_SHELL);
		}
		
		override public function listNotificationInterests():Array{
			return[PipeAwareModuleConstants.SEND_MESSAGE_MODULE];
		}
		
		override public function handleNotification(notification:INotification):void{
			switch(notification.getName()){
				case PipeAwareModuleConstants.SEND_MESSAGE_MODULE: 
					moduleSample.txtInfo.text = "Message from shell received";
				break;
				default: break;
			}
		}
		
		public function get moduleSample():ModuleSample{
			return viewComponent as ModuleSample;
		}
	}
}